/* --- General Widget Layout --- */
.thought-bubble-widget-container { 
    width: 100%; 
    box-sizing: border-box; 
    font-family: var(--tb-font-family);
    font-size: var(--tb-font-size);
}
.thought-bubble-widget { 
    width: 100%; 
    height: 100%; 
    background-color: var(--tb-bg-color); 
    border: 1px solid #444; 
    border-radius: 4px; 
    position: relative; 
    overflow: hidden; 
    user-select: none; 
}
.thought-bubble-world { 
    position: absolute; 
    top: 0; 
    left: 0; 
    width: 100%; 
    height: 100%; 
    transform-origin: 0 0; 
    background-color: transparent; 
}
.thought-bubble-grid { 
    position: absolute; 
    top: 0; 
    left: 0; 
    width: 100%; 
    height: 100%; 
    pointer-events: none; 
    background-color: transparent;
    background-image: linear-gradient(to right, var(--tb-grid-color) 1px, transparent 1px), linear-gradient(to bottom, var(--tb-grid-color) 1px, transparent 1px);
}

/* --- Toolbar --- */
.thought-bubble-toolbar { 
    position: absolute; 
    top: 0; 
    left: 0; 
    width: 100%; 
    height: 30px; 
    background-color: var(--tb-toolbar-bg-color); 
    z-index: 10; 
    padding: 0 5px; 
    box-sizing: border-box; 
    display: flex; 
    align-items: center; 
    gap: 10px; 
}
.thought-bubble-toolbar button, .thought-bubble-toolbar select { 
    padding: 4px 8px;
    background-color: var(--tb-button-bg-color);
    color: var(--tb-button-text-color);
    border: 1px solid var(--tb-box-border-color);
    border-radius: 4px;
}
.thought-bubble-toolbar label { 
    color: var(--tb-text-color); 
    font-size: 12px; 
}

/* --- Generic Box Styles --- */
.thought-bubble-box { 
    position: absolute; 
    background-color: var(--tb-box-bg-color); 
    border: 1px solid var(--tb-box-border-color); 
    border-radius: 4px; 
    display: flex; 
    flex-direction: column; 
    box-shadow: 2px 2px 10px var(--tb-box-shadow-color);
    z-index: 1; 
}
.thought-bubble-box.maximized { z-index: 100; }
.thought-bubble-box.minimized { 
    height: 28px !important; 
    min-height: 28px !important;
    overflow: hidden; 
}
.thought-bubble-box-header { 
    background-color: var(--tb-header-bg-color); 
    color: var(--tb-header-text-color);
    padding: 4px; 
    cursor: move; 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    height: 28px; 
    box-sizing: border-box; 
}
.thought-bubble-box-title { 
    background: none; 
    border: none; 
    color: var(--tb-header-text-color);
    font-weight: bold; 
    width: 100%; 
    cursor: move; 
    padding: 0; 
}
.thought-bubble-box-title:not([readonly]) { cursor: text; }
.thought-bubble-box-controls { display: flex; }
.thought-bubble-box-controls button { 
    background: none; 
    border: none; 
    color: var(--tb-header-text-color);
    cursor: pointer; 
    font-size: 14px; 
    padding: 0 4px; 
}
.thought-bubble-box-content { 
    flex-grow: 1; 
    box-sizing: border-box; 
    display: flex; 
    flex-direction: column; 
    overflow: hidden;
}
.thought-bubble-box-content textarea { 
    width: 100%; 
    height: 100%; 
    background-color: var(--tb-textarea-bg-color); 
    color: var(--tb-text-color);
    border: none; 
    resize: none; 
    padding: 5px; 
    box-sizing: border-box; 
}
.thought-bubble-box-resize-handle { 
    position: absolute; 
    bottom: 0; 
    right: 0; 
    width: 14px; 
    height: 14px; 
    cursor: se-resize; 
    background: var(--tb-accent-color);
    clip-path: polygon(100% 0, 100% 100%, 0 100%); 
}

/* --- Specific Box Type Styles --- */
.thought-bubble-box.text-box:not(.minimized) { min-width: 200px; min-height: 100px; }
.thought-bubble-box.controls-box:not(.minimized) { min-width: 300px; min-height: 200px; }
.thought-bubble-box.area-box:not(.minimized) { min-width: 500px; min-height: 500px; }

/* -- Controls Box -- */
.thought-bubble-box-content.controls-box { 
    display: flex; 
    flex-direction: column; 
    gap: 5px; 
    padding: 5px; 
    overflow: hidden; 
}
.controls-add-button { 
    width: 100%; 
    padding: 8px; 
    border-radius: 4px; 
    flex-shrink: 0;
    background-color: var(--tb-button-bg-color);
    color: var(--tb-button-text-color);
    border: 1px solid var(--tb-box-border-color);
}
.controls-variables-container { 
    display: flex; 
    flex-direction: column; 
    gap: 5px; 
    overflow-y: auto; 
}
.controls-variable-row { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 5px; align-items: center; }
.controls-variable-row input, .controls-variable-row select { 
    width: 100%; 
    background-color: var(--tb-textarea-bg-color); 
    color: var(--tb-text-color);
    border: 1px solid var(--tb-bg-color); 
    border-radius: 4px; 
    padding: 4px; 
}
.controls-variable-value { text-align: right; }
.controls-variable-delete { background: #5c2828; border: 1px solid #a14242; color: #fff; border-radius: 4px; cursor: pointer; width: 28px; height: 28px; }

/* -- Area Box -- */
.area-conditioning { padding: 4px; gap: 4px; }
.ac-toolbar { 
    display: flex; 
    align-items: center; 
    gap: 8px; 
    flex-shrink: 0; 
    flex-wrap: wrap; 
    height: auto; 
    min-height: 30px; 
}
.ac-control-group {
    display: flex;
    align-items: center;
    gap: 4px;
}
.ac-control-group label {
    white-space: nowrap;
}
.ac-toolbar input { width: 50px; background-color: var(--tb-textarea-bg-color); border: 1px solid var(--tb-bg-color); color: var(--tb-text-color); }
.ac-main-content { 
    flex-grow: 1; 
    display: flex; 
    flex-direction: row; 
    gap: 0; 
    overflow: hidden; 
}
.ac-canvas-container { 
    flex-grow: 1; 
    min-width: 150px; 
    position: relative; 
    display: flex;
}
.ac-canvas-container canvas { 
    position: absolute; 
    top: 0; 
    left: 0; 
    width: 100%; 
    height: 100%; 
    cursor: crosshair; 
}
.ac-textarea-container {
    display: flex;
    flex-direction: column;
    min-width: 100px;
}
.ac-divider {
    flex-shrink: 0;
    width: 10px;
    background-color: transparent;
    cursor: col-resize;
    transition: background-color 0.2s;
}
.ac-divider:hover {
    background-color: var(--tb-accent-color);
}

.ac-resize-handle {
    position: absolute;
    width: 12px;
    height: 12px;
    background: var(--tb-accent-color);
    border: 1px solid #111;
    z-index: 5;
    border-radius: 50%;
}
.ac-handle-nw, .ac-handle-se { cursor: nwse-resize; }
.ac-handle-ne, .ac-handle-sw { cursor: nesw-resize; }
.ac-handle-n, .ac-handle-s { cursor: ns-resize; }
.ac-handle-e, .ac-handle-w { cursor: ew-resize; }


/* --- Modals & Popups --- */
.lora-autocomplete-dropdown { 
    position: absolute; 
    background-color: var(--tb-box-bg-color, #2d2d2d);
    border: 1px solid var(--tb-box-border-color, #555);
    border-radius: 4px; 
    max-height: 200px; 
    overflow-y: auto; 
    z-index: 2100; 
    color: var(--tb-text-color, #ccc);
}
.lora-autocomplete-item { padding: 5px 10px; cursor: pointer; }
.lora-autocomplete-item:hover, .lora-autocomplete-item.selected { background-color: var(--tb-header-bg-color, #4a4a4a); }
.thought-bubble-modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.7); z-index: 2000; display: flex; align-items: center; justify-content: center; }
.thought-bubble-modal-content { background-color: #333; border: 1px solid #555; border-radius: 8px; padding: 20px; min-width: 400px; max-width: 90%; box-shadow: 0 5px 15px rgba(0,0,0,0.5); }
.thought-bubble-modal-title { margin-top: 0; color: #eee; }
.thought-bubble-modal-body { margin: 20px 0; color: #ccc; }
.thought-bubble-modal-body input { width: 100%; padding: 8px; box-sizing: border-box; background-color: #222; border: 1px solid #555; color: #ccc; border-radius: 4px; }
.thought-bubble-modal-footer { text-align: right; }
.thought-bubble-modal-footer button { margin-left: 10px; background-color: var(--tb-button-bg-color); color: var(--tb-button-text-color); }
.thought-bubble-file-list { max-height: 300px; overflow-y: auto; border: 1px solid #222; padding: 5px; background-color: #282828; }
.thought-bubble-file-item { padding: 8px 12px; cursor: pointer; border-bottom: 1px solid #333; }
.thought-bubble-file-item:hover { background-color: #4a4a4a; }
.thought-bubble-file-item:last-child { border-bottom: none; }
.thought-bubble-context-menu { 
    display: none; 
    position: absolute; 
    background-color: var(--tb-box-bg-color, #2d2d2d);
    border: 1px solid var(--tb-box-border-color, #555);
    border-radius: 4px; 
    min-width: 150px; 
    z-index: 2200; 
    color: var(--tb-text-color, #ccc);
    padding: 5px; 
}
.thought-bubble-context-menu-item { padding: 8px 12px; cursor: pointer; }
.thought-bubble-context-menu-item:hover { background-color: var(--tb-header-bg-color, #4a4a4a); }
.theme-editor-row { display: grid; grid-template-columns: 1fr 1fr auto; align-items: center; gap: 10px; margin-bottom: 5px; }
.theme-editor-row label { text-transform: capitalize; }

.thought-bubble-theme-header {
    font-weight: bold;
    color: #aaa;
    margin-top: 10px;
    margin-bottom: 5px;
    padding: 0 12px;
    font-size: 12px;
    text-transform: uppercase;
}

.thought-bubble-modal-body hr {
    border: none;
    border-top: 1px solid #444;
    margin: 10px 0;
}

.theme-editor-row input[type="color"] {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    width: 100%;
    height: 28px;
    background-color: transparent;
    border: 1px solid var(--tb-box-border-color);
    cursor: pointer;
}

.theme-editor-row input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 4px;
}

.theme-editor-row input[type="color"]::-moz-color-swatch {
    border: none;
    border-radius: 4px;
}

